package com.huawei.appgallery.forum.message.card;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.message.bean.ForumMsgSettingItemCardBean;
import com.huawei.appgallery.forum.message.card.ForumBuoyMsgSwitchSettingItemCard.b;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import huawei.widget.HwTextView;
import o.bqx;
import o.brc.e;
import o.bvj;
import o.bvj.j;
import o.bvt;
import o.bwc;
import o.bwj;
import o.bwl;
import o.cgz;
import o.doo;
import o.evk;

public class ForumLauncherMsgSwitchSettingItemCard extends ForumCard implements OnTouchListener, OnCheckedChangeListener {
    private View ʽ;
    private long ˊ = 0;
    private Switch ˋ;
    protected boolean ˎ = false;
    private b ˏ;
    protected ForumMsgSettingItemCardBean ॱ;
    private HwTextView ᐝ;

    public ForumLauncherMsgSwitchSettingItemCard(Context context) {
        super(context);
    }

    public void ˋ(b bVar) {
        this.ˏ = bVar;
    }

    public cgz ˏ(View view) {
        ʽ(view);
        this.ˋ = (Switch) view.findViewById(bvj.b.ˉॱ);
        this.ᐝ = (HwTextView) view.findViewById(bvj.b.ʾॱ);
        this.ʽ = view.findViewById(bvj.b.ˋॱ);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        if (cardBean instanceof ForumMsgSettingItemCardBean) {
            this.ॱ = (ForumMsgSettingItemCardBean) cardBean;
            this.ᐝ.setText(this.ʼॱ.getResources().getString(this.ॱ.ʽ()));
            this.ˋ.setChecked(this.ॱ.ᐝ());
            this.ˋ.setOnTouchListener(this);
            this.ˋ.setOnCheckedChangeListener(this);
            this.ʽ.setVisibility(this.ॱ.ʼ() == 1 ? 0 : 8);
        }
    }

    public boolean onTouch(View view, MotionEvent motionEvent) {
        long currentTimeMillis = System.currentTimeMillis();
        if (Math.abs(currentTimeMillis - this.ˊ) <= 1000) {
            return true;
        }
        if (doo.ˊ(this.ʼॱ)) {
            return this.ˎ;
        }
        this.ˊ = currentTimeMillis;
        evk.ˋ(this.ʼॱ, this.ʼॱ.getString(j.ꓸ), 0).ˋ();
        return true;
    }

    public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
        this.ˎ = true;
        if (this.ॱ != null) {
            ˋ(z);
        }
    }

    protected void ˋ(final boolean z) {
        new bwc().ˎ(this.ॱ.ˊ(), z, new e<bwj, bwl>(this) {
            final /* synthetic */ ForumLauncherMsgSwitchSettingItemCard ˏ;

            public /* synthetic */ void ˋ(Object obj, Object obj2) {
                ॱ((bwj) obj, (bwl) obj2);
            }

            public /* synthetic */ void ˏ(Object obj, Object obj2) {
                ˊ((bwj) obj, (bwl) obj2);
            }

            public void ˊ(bwj o_bwj, bwl o_bwl) {
            }

            public void ॱ(bwj o_bwj, bwl o_bwl) {
                this.ˏ.ˊ(z, o_bwl);
            }
        });
    }

    protected void ˊ(boolean z, bvt o_bvt) {
        boolean z2 = false;
        this.ˎ = false;
        if (o_bvt == null) {
            bqx.ˋ("ForumLauncherMsgSetting", "response error");
        } else if (o_bvt.getResponseCode() != 0 || o_bvt.getRtnCode_() != 0) {
            if (o_bvt.getResponseCode() != 3 || doo.ˊ(this.ʼॱ)) {
                evk.ˋ(this.ʼॱ, this.ʼॱ.getString(j.ॱʼ), 0).ˋ();
            } else {
                evk.ˋ(this.ʼॱ, this.ʼॱ.getString(j.ꓸ), 0).ˋ();
            }
            this.ˋ.setOnCheckedChangeListener(null);
            Switch switchR = this.ˋ;
            if (!z) {
                z2 = true;
            }
            switchR.setChecked(z2);
            this.ˋ.setOnCheckedChangeListener(this);
            if (this.ˏ != null && this.ॱ != null) {
                this.ˏ.ˎ(this.ॱ.ˊ(), z);
            }
        } else if (this.ॱ != null) {
            this.ॱ.ˎ(z);
            if (this.ˏ != null) {
                this.ˏ.ˎ(this.ॱ.ˊ(), z);
            }
        }
    }
}
